#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
using namespace std;

int r[1000];
int q[1000];
int digitOccurs[100][10];
int main3720()
{


	int n,k;

	for (int n = 2;n <= 100;n++)
	{
		int i = 1;
		r[i] = 1;
		while (true)
		{
			int j;
			bool found = false;
			for (int t = 1;t <= i - 1;t ++)
			{
				if (r[i] == r[t])
				{
					j = t;
					found = true;
				}
			}
			if (found)
			{
				memset(digitOccurs[n],0,sizeof(int) * 10);
				for (int t = 1;t <= i - 1;t++)
				{
					digitOccurs[n][q[t]] ++;
				}
				break;
			}
			q[i] = (10 * r[i]) / n;
			r[i + 1] = 10 * r[i] - q[i] * n;
			if (r[i + 1] == 0)
			{
				memset(digitOccurs[n],0,sizeof(int) * 10);
				for (int t = 1;t <= i;t++)
				{
					digitOccurs[n][q[t]] ++;
				}
				break;
			}
			i ++;
		}
	}
	while (cin >> n >> k)
	{
		int sum = 0;
		for (int i = 2;i<=n;i++)
		{
			sum += digitOccurs[i][k];
		}
		cout << sum << endl;
	}
	return 0;
}